#include<iostream>
#include<string.h>
#include<mysql/mysql.h>
#include<stdlib.h>
#include<semaphore.h>
#include"tcpsever.h"
using namespace std;
MYSQL *mpcon = mysql_init((MYSQL *)0);
sem_t sem;
sem_t semcount;
int main(int argc,char **argv)
{
	//ip   port   pth_num
	char *ip=argv[1];
	unsigned short port=(unsigned short) (atoi(argv[2]));
	int pthnum=atoi(argv[3]);

	if(pthnum>100||pthnum<1)
	{
	cout<<"pthnum number is error!\n"<<endl;
	exit(0);
	}

	if(port<1200)
	{
	cout<<"can't use under 1200 port!\n"<<endl;
	exit(0);
	}
	
		if(!mysql_real_connect(mpcon,"127.0.0.1","root","123456",NULL,3306,NULL,0))
	{
		cout<<"sql connect fail!"<<endl;
		return 0;
	}
	//选择数据库       数据库指针  库名
	if(mysql_select_db(mpcon,"chat"))
	{
		cout<<"select fail!"<<endl;
		return 0;
	}

    sem_init(&sem,0,1);
	sem_init(&semcount,0,1);
	
	//构造服务器对象
	tcpsever ser(ip,port,pthnum);
	
	//运行服务器
	ser.run();

	return 0;
}
